#include "directory.h"
#include <stdio.h>
#include <iostream>
#include <string>
#include "lib/e7convert.h"

Directory::Directory(FILE* device, unsigned long offset) : Block(device, offset)
{
	dir = new directory_t();
	read(dir, sizeof(directory_t));
}

Directory::~Directory()
{
	delete dir;
}

ushort Directory::getInodeNr()
{
	return readUnsignedInteger(dir->inodeNr, USHORT);
}

string Directory::getFilename()
{
	return getchars((byte*)dir->filename, 0, 14);
}

void Directory::print()
{
	//only print dirs that have valid inodes..
	if(getInodeNr()!=0)
	{
		printf("Inode Nr: %d\t", getInodeNr());
		printf("Filename: %s\n", dir->filename);
	}
}
